#include <graphics.h>

static int dealbit(int a, float dt) {
    a = int(a * dt);
    if ( a>255 )    a = 255;
    else if ( a<0 ) a = 0;
    return a;
}
static int getchangcolor(int Color, float t) {
    int r = EGEGET_R(Color), g = EGEGET_G(Color), b = EGEGET_B(Color);
    r = dealbit(r, t);
    g = dealbit(g, t);
    b = dealbit(b, t);
    return EGERGB(r, g, b);
}
void drawedge(int x, int y, int w, int h, int color, int bdark = 1) {
    setcolor(getchangcolor(color, 1.5f));
    line(x, y+h, x, y);
    lineto(x+w, y);
    if ( bdark )
        setcolor(getchangcolor(color, 0.7f));
    lineto(x+w, y+h);
    lineto(x, y+h);
}
void drawtile(int x, int y, int w, int h, int d, int color) {
    w-=d, h-=d;
    setfillcolor(color);
    bar(x+d, y+d, x+w, y+h);
    drawedge(x, y, w, h, color);
    drawedge(x+d, y+d, w-2*d, h-2*d, color);
}